// src/components/MissionTypeModal.tsx
import React from "react";
import type { MissionType } from "../App"; // 导入 MissionType 类型

interface MissionTypeModalProps {
  isOpen: boolean;
  onClose: () => void;
  onSelect: (type: MissionType) => void;
}

const MissionTypeModal: React.FC<MissionTypeModalProps> = ({
  isOpen,
  onClose,
  onSelect,
}) => {
  if (!isOpen) return null;

  const missionTypes = [
    {
      id: "mapping",
      name: "建图航拍",
      icon: "https://www.dji.com/img/dji-terra/mission-type-mapping.svg",
    },
    {
      id: "oblique",
      name: "倾斜摄影",
      icon: "https://www.dji.com/img/dji-terra/mission-type-oblique.svg",
    },
    {
      id: "waypoint",
      name: "航点飞行",
      icon: "https://www.dji.com/img/dji-terra/mission-type-waypoint.svg",
      disabled: true,
    },
    {
      id: "strip",
      name: "带状航线",
      icon: "https://www.dji.com/img/dji-terra/mission-type-strip.svg",
      disabled: true,
    },
    {
      id: "inspection",
      name: "精细化巡检",
      icon: "https://www.dji.com/img/dji-terra/mission-type-inspection.svg",
      disabled: true,
    },
  ];

  return (
    <div className="fixed inset-0 bg-black bg-opacity-70 flex justify-center items-center z-[1000] transition-opacity duration-300">
      <div className="bg-[#2a2a2a] rounded-lg p-6 w-[700px] max-w-[90%] shadow-lg text-[#e0e0e0]">
        <div className="flex justify-between items-center mb-6 pb-4 border-b border-[#3a3a3a]">
          <h3 className="text-xl font-semibold">选择任务类型</h3>
          <button
            className="text-[#a0a0a0] text-3xl cursor-pointer hover:text-[#e0e0e0]"
            onClick={onClose}
          >
            &times;
          </button>
        </div>
        <div className="grid grid-cols-auto-fit-minmax-120 gap-5">
          {missionTypes.map((type) => (
            <div
              key={type.id}
              className={`flex flex-col items-center p-4 bg-[#3a3a3a] border border-[#4a4a4a] rounded-lg cursor-pointer transition-colors duration-300
                                ${
                                  type.disabled
                                    ? "opacity-50 cursor-not-allowed"
                                    : "hover:bg-[#4a4a4a] hover:border-[#007bff]"
                                }`}
              onClick={() => !type.disabled && onSelect(type.id as MissionType)}
            >
              <img
                src={type.icon}
                alt={type.name}
                className="w-16 h-16 mb-2 invert brightness-150"
              />
              <span className="text-sm text-center text-[#c0c0c0]">
                {type.name}
              </span>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
};

export default MissionTypeModal;
